home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / smailsrc.zip / UUPC.ZIP / HOST.C < prev    next >
Text File  |  1990-04-04  |  4KB  |  174 lines

  1. /*
  2.    ibmpc/host.c
  3.  
  4.    IBM-PC host program
  5. */
  6.  
  7. #include <stdio.h>
  8. #include <setjmp.h>
  9. #include <errno.h>
  10. #include <stdlib.h>
  11. #include <alloc.h>
  12. #include <assert.h>
  13. #include <fcntl.h>
  14.  
  15. #include "lib.h"
  16. #include "host.h"
  17.  
  18. char *mailbox, *name, *homedir;
  19. char *maildir, *newsdir, *confdir, *spooldir, *pubdir, *tempdir;
  20. char *domain, *nodename, *mailserv;
  21. int E_tzoffset;
  22. char *E_tzname;
  23. char *E_indevice, *E_inspeed;
  24. char *E_editor, *E_pager;
  25. char *E_filesent, *E_signature;
  26.  
  27. jmp_buf    dcpexit;
  28.  
  29. int main(argc, argv)
  30. int argc;
  31. char *argv[];
  32. {
  33. #ifdef CWDSPOOL
  34.     char *currdir;
  35. #endif
  36.     int status;
  37.  
  38.     if (!configure())
  39.         return 1;    /* system configuration failed */
  40.  
  41.     /* Turbo C needs these for time() to work right. */
  42.     daylight = 0;
  43.     timezone = - E_tzoffset * 60;
  44.  
  45. #ifdef CWDSPOOL
  46.     /* move to the spooling directory */
  47.     currdir = getcwd(nil(char), 80);
  48.     CHDIR(spooldir);
  49. #endif
  50.  
  51.     /* setup longjmp for error exit's */
  52.     status = 10;    /* set default in case we get out via a longjmp */
  53.     if (setjmp(dcpexit) == 0)
  54.         status = MAIN(argc, argv);
  55.  
  56. #ifdef CWDSPOOL
  57.     /* go back to the start-up directory */
  58.     CHDIR(currdir);
  59. #endif
  60.  
  61.     return status;
  62.  
  63. } /*main*/
  64.  
  65.  
  66. /*
  67.    importpath - convert a canonical name to a format the host can handle
  68.  
  69.    Thise routines convert file name between canonical form, which is
  70.    defined as a 'unix' style pathname, and the MS-DOS all uppercase
  71.    "xxxxxxxx.xxx" format.
  72.  
  73.    Mung the canonical file name as follows:
  74.      1 - skip any path from the canonical name
  75.      2 - copy up to 8 character from the canonical name converting . to _
  76.          and uppercase to lowercase.
  77.      3 - if the name was longer than 8 character copy a . to the host name
  78.          and then copy the up to three characters from the tail of the
  79.          canonical name to the host name.
  80. */
  81.  
  82. #define min(x,y) (((x) < (y)) ? (x) : (y))
  83.  
  84. void importpath(host, canon)
  85. char *host, *canon;
  86. {
  87.    char *s, *out, c;
  88.    int i, j, l;
  89.  
  90.    out = host;
  91.  
  92.    /* get a pointer to the last component of the path */
  93.    if ((s = strrchr(canon, '/')) == (char *)NULL)
  94.       s = canon;
  95.    else
  96.       s++;
  97.  
  98.    j = min(l = strlen(s), 8);
  99.  
  100.    for (i = 0; i < j; i++) {
  101.       c = *s++;
  102.       *out++ = (c == '.') ? '_' : tolower(c);
  103.    }
  104.    *out = '\0';
  105.  
  106.    while (*s != '\0') s++;
  107.  
  108.    if (l>8)
  109.       for (i=0; i<3; i++)
  110.          if (*--s == '.') {
  111.             s++;
  112.             break;
  113.          }
  114.  
  115.    if (*s != '\0') {
  116.       (void)strcat(out, ".");
  117.       (void)strcat(out, s);
  118.    }
  119.  
  120. } /*importpath*/
  121.  
  122.  
  123. /*
  124.    mkfilename - build a path name out of a directory name and a file name
  125. */
  126.  
  127. void mkfilename(pathname, path, name)
  128. char *pathname, *path, *name;
  129. {
  130.  
  131.    sprintf(pathname, "%s/%s", path, name);
  132.  
  133. } /*mkfilename*/
  134.  
  135.  
  136. /*
  137.     getrcnames - return the name of the configuration files
  138. */
  139.  
  140. #define    SYSRCSYM    "UUPCSYSRC"
  141. #define USRRCSYM    "UUPCUSRRC"
  142.  
  143. int getrcnames(sysp, usrp)
  144. char **sysp, **usrp;
  145. {
  146.  
  147.     if ((*sysp = getenv(SYSRCSYM)) != nil(char))
  148.         *sysp = strcpy(malloc(strlen(*sysp) + 1), *sysp);
  149.     else {
  150.         printf("environment variable %s must be specified\n", SYSRCSYM);
  151.         return FALSE;
  152.     }
  153.  
  154.     if ((*usrp = getenv(USRRCSYM)) != nil(char))
  155.         *usrp = strcpy(malloc(strlen(*usrp) + 1), *usrp);
  156.  
  157.     return TRUE;
  158.  
  159. } /*getrcnames*/
  160.  
  161.  
  162. /*
  163.     filemode - default the text/binary mode for subsequently opened files
  164. */
  165.  
  166. void filemode(mode)
  167. char mode;
  168. {
  169.  
  170.    assert((mode == BINARY) || (mode == TEXT));
  171.    _fmode = (mode == TEXT) ? O_TEXT : O_BINARY;
  172.  
  173. } /*filemode*/
  174.